<template>
  <el-dialog :title="!dataForm.id ? '新增' : '修改'" :close-on-click-modal="false" :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
      <el-form-item label="" prop="userId">
        <el-input v-model="dataForm.userId" placeholder=""></el-input>
      </el-form-item>
      <el-form-item label="" prop="schoolId">
        <el-input v-model="dataForm.schoolId" placeholder=""></el-input>
      </el-form-item>
      <el-form-item label="" prop="level">
        <el-input v-model="dataForm.level" placeholder=""></el-input>
      </el-form-item>
      <el-form-item label="" prop="file">
        <el-input v-model="dataForm.file" placeholder=""></el-input>
      </el-form-item>
      <el-form-item label="" prop="conclusionPostpone">
        <el-input v-model="dataForm.conclusionPostpone" placeholder=""></el-input>
      </el-form-item>
      <el-form-item label="" prop="passCount">
        <el-input v-model="dataForm.passCount" placeholder=""></el-input>
      </el-form-item>
      <el-form-item label="" prop="noPass">
        <el-input v-model="dataForm.noPass" placeholder=""></el-input>
      </el-form-item>
      <el-form-item label="" prop="peopleNumber">
        <el-input v-model="dataForm.peopleNumber" placeholder=""></el-input>
      </el-form-item>
      <el-form-item label="" prop="statu">
        <el-input v-model="dataForm.statu" placeholder=""></el-input>
      </el-form-item>
      <el-form-item label="" prop="createTime">
        <el-input v-model="dataForm.createTime" placeholder=""></el-input>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
export default {
  data() {
    return {
      visible: false,
      dataForm: {
        id: 0,
        userId: '',
        schoolId: '',
        level: '',
        file: '',
        conclusionPostpone: '',
        passCount: '',
        noPass: '',
        peopleNumber: '',
        statu: '',
        createTime: ''
      },
      dataRule: {
        userId: [
          { required: true, message: '不能为空', trigger: 'blur' }
        ],
        schoolId: [
          { required: true, message: '不能为空', trigger: 'blur' }
        ],
        level: [
          { required: true, message: '不能为空', trigger: 'blur' }
        ],
        file: [
          { required: true, message: '不能为空', trigger: 'blur' }
        ],
        conclusionPostpone: [
          { required: true, message: '不能为空', trigger: 'blur' }
        ],
        passCount: [
          { required: true, message: '不能为空', trigger: 'blur' }
        ],
        noPass: [
          { required: true, message: '不能为空', trigger: 'blur' }
        ],
        peopleNumber: [
          { required: true, message: '不能为空', trigger: 'blur' }
        ],
        statu: [
          { required: true, message: '不能为空', trigger: 'blur' }
        ],
        createTime: [
          { required: true, message: '不能为空', trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    init(id) {
      this.dataForm.id = id || 0
      this.visible = true
      this.$nextTick(() => {
        this.$refs['dataForm'].resetFields()
        if (this.dataForm.id) {
          this.$http({
            url: this.$http.adornUrl(`/sys/conclusion/info/${this.dataForm.id}`),
            method: 'get',
            params: this.$http.adornParams()
          }).then(({ data }) => {
            if (data && data.code === 0) {
              this.dataForm.userId = data.conclusion.userId
              this.dataForm.schoolId = data.conclusion.schoolId
              this.dataForm.level = data.conclusion.level
              this.dataForm.file = data.conclusion.file
              this.dataForm.conclusionPostpone = data.conclusion.conclusionPostpone
              this.dataForm.passCount = data.conclusion.passCount
              this.dataForm.noPass = data.conclusion.noPass
              this.dataForm.peopleNumber = data.conclusion.peopleNumber
              this.dataForm.statu = data.conclusion.statu
              this.dataForm.createTime = data.conclusion.createTime
            }
          })
        }
      })
    },
    // 表单提交
    dataFormSubmit() {
      this.$refs['dataForm'].validate((valid) => {
        if (valid) {
          this.$http({
            url: this.$http.adornUrl(`/sys/conclusion/${!this.dataForm.id ? 'save' : 'update'}`),
            method: 'post',
            data: this.$http.adornData({
              'id': this.dataForm.id || undefined,
              'userId': this.dataForm.userId,
              'schoolId': this.dataForm.schoolId,
              'level': this.dataForm.level,
              'file': this.dataForm.file,
              'conclusionPostpone': this.dataForm.conclusionPostpone,
              'passCount': this.dataForm.passCount,
              'noPass': this.dataForm.noPass,
              'peopleNumber': this.dataForm.peopleNumber,
              'statu': this.dataForm.statu,
              'createTime': this.dataForm.createTime
            })
          }).then(({ data }) => {
            if (data && data.code === 0) {
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500,
                onClose: () => {
                  this.visible = false
                  this.$emit('refreshDataList')
                }
              })
            } else {
              this.$message.error(data.msg)
            }
          })
        }
      })
    }
  }
}
</script>
